package com.beiding.workordersystem.orders.looporder.controller;

import com.beiding.workordersystem.common.standard.R;
import com.beiding.workordersystem.orders.looporder.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/loopOrder/statistics")
public class LoopOrderStatisticsController {

    @Autowired
    private OrderService service;

    @GetMapping("/order")
    R order(Date start, Date to){
        return R.ok(service.statistics(start, to));
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

}
